//------------Sonic CD Crumble Ledge 3 Script-------------//
//--------Scripted by Christian Whitehead 'The Taxman'--------//
//-------Unpacked By Rubberduckycooly's Script Unpacker-------//

//-------Aliases-------//
#alias 54: TYPE_CRUMBLELEDGE3


sub ObjectMain
	switch Object.State
	case 1
		if Object.Value2>0
			Object.Value2--
		else
			PlayStageSfx(0,0)
			Object.State=4
		endif
		break
	case 2
		if Object.Value2>0
			Object.Value2--
		else
			PlayStageSfx(0,0)
			Object.State=3
		endif
		break
	case 3
		Object.Value2++
		if Object.Value2==12
			Object.Value2=0
			if Object.Value0<Object.Value1
				Object.Value3--
				Object.Value0+=16
				TempValue0=Object.Value0
				TempValue0-=8
				TempValue0<<=16
				TempValue0+=Object.XPos
				CreateTempObject(TypeName[CrumbleLedge3],0,TempValue0,Object.YPos)
				Object[TempObjectPos].State=6
			else
				ResetObjectEntity(Object.EntityNo,TypeName[BlankObject],0,0,0)
			endif
		endif
		break
	case 4
		Object.Value2++
		if Object.Value2==12
			Object.Value2=0
			if Object.Value1>Object.Value0
				Object.Value3--
				Object.Value1-=16
				TempValue0=Object.Value1
				TempValue0+=8
				TempValue0<<=16
				TempValue0+=Object.XPos
				CreateTempObject(TypeName[CrumbleLedge3],0,TempValue0,Object.YPos)
				Object[TempObjectPos].State=6
			else
				ResetObjectEntity(Object.EntityNo,TypeName[BlankObject],0,0,0)
			endif
		endif
		break
	case 5
		if Object.OutOfBounds==1
			Object.State=0
			Object.Value3=Object.PropertyValue
			Object.Value0=Object.PropertyValue
			Object.Value0<<=3
			Object.Value1=Object.Value0
			FlipSign(Object.Value0)
			Object.Priority=0
			Object.Value2=0
		endif
		break
	case 6
		Object.Value4+=16384
		if Object.Value4>0
			Object.YPos+=Object.Value4
		endif
		if Object.OutOfBounds==1
			Object.Type=TypeName[BlankObject]
		endif
		break

	endswitch
endsub


sub ObjectPlayerInteraction
	if Object.State==0
		PlayerObjectCollision(C_PLATFORM,Object.Value0,-17,Object.Value1,16)
		if CheckResult==1
			Object.Value2=1
			Object.Priority=1
			if Player.XPos>Object.XPos
				Object.State=1
			else
				Object.State=2
			endif
		endif
	else
		PlayerObjectCollision(C_PLATFORM,Object.Value0,-17,Object.Value1,16)
	endif
endsub


sub ObjectDraw
	switch Object.State
	case 0
	case 1
	case 2
	case 4
		TempValue0=0
		TempValue1=Object.Value0
		TempValue1<<=16
		TempValue1+=524288
		TempValue1+=Object.XPos
		while TempValue0<Object.Value3
			DrawSpriteXY(0,TempValue1,Object.YPos)
			TempValue0++
			TempValue1+=1048576
		loop
		break
	case 3
		TempValue0=0
		TempValue1=Object.Value1
		TempValue1<<=16
		TempValue1-=524288
		TempValue1+=Object.XPos
		while TempValue0<Object.Value3
			DrawSpriteXY(0,TempValue1,Object.YPos)
			TempValue0++
			TempValue1-=1048576
		loop
		break
	case 6
		DrawSprite(Object.Frame)
		break

	endswitch
endsub


sub ObjectStartup
	LoadSpriteSheet("R1/Objects2.gif")
	ArrayPos0=32
	while ArrayPos0<1056
		if Object[ArrayPos0].Type==TypeName[CrumbleLedge3]
			Object[ArrayPos0].Value3=Object[ArrayPos0].PropertyValue
			Object[ArrayPos0].Value0=Object[ArrayPos0].PropertyValue
			Object[ArrayPos0].Value0<<=3
			Object[ArrayPos0].Value1=Object[ArrayPos0].Value0
			FlipSign(Object[ArrayPos0].Value0)
		endif
		ArrayPos0++
	loop
	SpriteFrame(-8,-32,16,48,163,1)
endsub

sub RSDK
	LoadSpriteSheet("Global/Display.gif")
	SetEditorIcon(Icon0,SingleIcon,-16,-16,32,32,1,143)
endsub
